package com.bb.blog.web.constant;

import org.springframework.http.HttpStatus;

public enum CommonServerExceptionEnum implements ServerExceptionEnum {
    SERVER_400(HttpStatus.BAD_REQUEST),
    SERVER_401(HttpStatus.UNAUTHORIZED),
    SERVER_403(HttpStatus.FORBIDDEN),
    SERVER_404(HttpStatus.NOT_FOUND),
    SERVER_500(HttpStatus.INTERNAL_SERVER_ERROR),

    /**
     * 鉴权
     */
    SECURITY_EXCEPTION(400, "认证异常", null),
    BAD_CREDENTIALS(400, "账号或密码错误", null),
    ACCOUNT_STATUS_EXCEPTION(400, "账号状态异常", "请联系系统管理员处理异常"),
    TOKEN_GRANT_EXCEPTION(401, "token无效", null),
    TOKEN_INVALID(401, "token已过期,请重新登录", null),

    /**
     * 表单校验
     */
    ADD_MENU_ERROR(400, "菜单CODE已存在", null);


    private String msg;
    private Integer code;
    private Object data;

    CommonServerExceptionEnum(HttpStatus httpStatus) {
        this(httpStatus.value(), httpStatus.getReasonPhrase(), null);
    }

    CommonServerExceptionEnum(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    @Override
    public Object getData() {
        return data;
    }
}
